using JEngine.Framework;
using UnityEngine.UI;
using UnityEngine;

public class HUDPanel : Panel
{
    public static HUDPanel instance;
    private GameObject topRoot;

    private HUDManager hudMgr = new HUDManager();

    

    public HUDItem Add(Transform root, GameObject type)
    {
      return  hudMgr.Add(root.gameObject, type, topRoot.transform);
    }

    public void RemoveType(GameObject go, GameObject type)
    {
        hudMgr.RemoveType(go, type);
    }

    public void Remove(GameObject go)
    {
        hudMgr.Remove(go);
    }

    void LateUpdate()
    {
        foreach (var d in hudMgr.Get())
        {
            if (d.Key == null)
                continue;
            for (int i = 0; i < d.Value.Count; i++)
            {
                d.Value[i].Check(d.Key.transform.position);
            }
        }
    }

    protected override void InitComponent()
    {
        base.InitComponent();
        instance = this;
        topRoot = new GameObject();
        topRoot.SetParent(transform);
        topRoot.transform.localPosition = Vector3.zero;
        topRoot.transform.localScale=Vector3.one;
        topRoot.AddMissingComponent<RectTransform>().anchorMax = Vector2.zero;
        topRoot.AddMissingComponent<RectTransform>().anchorMin = Vector2.zero;
    }

    protected override void OnLoad(params object[] parameters)
    {
       
    }
}